package com.suse.ecommerce.serviceImp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.suse.ecommerce.dao.OrderMapper;
import com.suse.ecommerce.pojo.Order;
import com.suse.ecommerce.pojo.OrderExample;
import com.suse.ecommerce.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public void addOrder(Order order){
        orderMapper.insertSelective(order);
    }

    @Override
    public void updateOrder(Order order, String orderId) {
        order.setOrderId(orderId);
        orderMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    public PageInfo<Order> queryOrder(Order order,int pn) {
        PageHelper.startPage(pn,5);
        List<Order> list = orderMapper.queryOrders(order);
        PageInfo pageInfo = new PageInfo(list,5);
        return pageInfo;
    }

    //根据id设置order的status
    @Override
    public void updateOrderStatusById(Order order) {
        orderMapper.updateByPrimaryKeySelective(order);
    }
}
